package de.easywakeup.data;

import java.util.ArrayList;
import java.util.HashMap;

import android.media.MediaPlayer;
import android.widget.ArrayAdapter;
import de.easywakeup.appService.AppService;
import de.easywakeup.appService.TimerHandler;
import de.easywakeup.gui.AlarmSettings;
import de.easywakeup.gui.MainScreen;
import de.easywakeup.yahooWeather.GetWeather;
import de.easywakeup.yahooWeather.GetWoeid;

public class Data
{
	private static Data data;

	// transient is the declaration that the objects are not serializiert when
	// saving. The fields are not taken into account for the Persistence.
	private transient AppService appService;
	private static transient GetWoeid getWoeid;
	private static transient GetWeather getWeather;
	private static transient TimerHandler timerHandler;

	// Gui
	private transient MainScreen mainScreen;
	private transient AlarmSettings alarmSettings;

	private transient ArrayAdapter< String > adapterListViewMain;

	private ArrayList< AlarmList > alarmList = new ArrayList< AlarmList >( );

	// Data of Weather
	private long lastWheaterUpdate = 0;

	private String woeid = "";
	private String temperature = Integer.MAX_VALUE + "";
	private String date = "";
	private String humidity = "";

	private String description = "";
	private String city = "";
	private String region = "";
	private String country = "";

	private String windChill = "";
	private String windDirection = "";
	private String windSpeed = "";

	private String atmosphereChill = "";
	private String atmosphereVisibility = "";
	private String atmospherePressure = "";
	private String atmosphereRising = "";

	private String sunrise = "";
	private String sunset = "";

	private String conditiontext = "";
	private String conditiondate = "";

	// Data of Settings
	private String timeBeforeMeeting = "0";
	private String timeAutoChange = "0";
	private String location = "";
	private int language;

	// MusikPlayer
	MediaPlayer mediaPlayer;

	// Temp Values
	HashMap< String, String > temp_chooseMusik;

	private String lastUsedAlert;

	// Verify the redundancy of the certain object
	public static Data singleton( )
	{
		if( data == null )
		{
			data = new Data( );
		}
		return data;
	}

	public void setAppService( AppService appService )
	{
		this.appService = appService;
	}

	public String getTimeBeforeMeeting( )
	{
		return timeBeforeMeeting;
	}

	public void setTimeBeforeMeeting( String timeBeforeMeeting )
	{
		this.timeBeforeMeeting = timeBeforeMeeting;
	}

	public String getTimeAutoChange( )
	{
		return timeAutoChange;
	}

	public void setTimeAutoChange( String timeAutoChange )
	{
		this.timeAutoChange = timeAutoChange;
	}

	public String getLocation( )
	{
		return location;
	}

	public void setLocation( String location )
	{
		this.location = location;
	}

	public int getLanguage( )
	{
		return language;
	}

	public void setLanguage( int language )
	{
		this.language = language;
	}

	public Data getData( )
	{
		return data;
	}

	public void setData( Data data )
	{
		Data.data = data;
	}

	public AppService getAppService( )
	{
		return appService;
	}

	public String getTemperature( )
	{
		return temperature;
	}

	public void setTemperature( String temperature )
	{
		this.temperature = temperature;
	}

	public String getDate( )
	{
		return date;
	}

	public void setDate( String date )
	{
		this.date = date;
	}

	public String getHumidity( )
	{
		return humidity;
	}

	public void setHumidity( String humidity )
	{
		this.humidity = humidity;
	}

	public String getWoeid( )
	{
		return woeid;
	}

	public void setWoeid( String woeid )
	{
		this.woeid = woeid;
	}

	public String getDescription( )
	{
		return description;
	}

	public void setDescription( String description )
	{
		this.description = description;
	}

	public String getCity( )
	{
		return city;
	}

	public void setCity( String city )
	{
		this.city = city;
	}

	public String getRegion( )
	{
		return region;
	}

	public void setRegion( String region )
	{
		this.region = region;
	}

	public String getCountry( )
	{
		return country;
	}

	public void setCountry( String country )
	{
		this.country = country;
	}

	public String getWindChill( )
	{
		return windChill;
	}

	public void setWindChill( String windChill )
	{
		this.windChill = windChill;
	}

	public String getWindDirection( )
	{
		return windDirection;
	}

	public void setWindDirection( String windDirection )
	{
		this.windDirection = windDirection;
	}

	public String getWindSpeed( )
	{
		return windSpeed;
	}

	public void setWindSpeed( String windSpeed )
	{
		this.windSpeed = windSpeed;
	}

	public String getSunrise( )
	{
		return sunrise;
	}

	public void setSunrise( String sunrise )
	{
		this.sunrise = sunrise;
	}

	public String getSunset( )
	{
		return sunset;
	}

	public void setSunset( String sunset )
	{
		this.sunset = sunset;
	}

	public String getConditiontext( )
	{
		return conditiontext;
	}

	public void setConditiontext( String conditiontext )
	{
		this.conditiontext = conditiontext;
	}

	public String getConditiondate( )
	{
		return conditiondate;
	}

	public void setConditiondate( String conditiondate )
	{
		this.conditiondate = conditiondate;
	}

	public String getAtmosphereChill( )
	{
		return atmosphereChill;
	}

	public void setAtmosphereChill( String atmosphereChill )
	{
		this.atmosphereChill = atmosphereChill;
	}

	public String getAtmosphereVisibility( )
	{
		return atmosphereVisibility;
	}

	public void setAtmosphereVisibility( String atmosphereVisibility )
	{
		this.atmosphereVisibility = atmosphereVisibility;
	}

	public String getAtmospherePressure( )
	{
		return atmospherePressure;
	}

	public void setAtmospherePressure( String atmospherePressure )
	{
		this.atmospherePressure = atmospherePressure;
	}

	public String getAtmosphereRising( )
	{
		return atmosphereRising;
	}

	public void setAtmosphereRising( String atmosphereRising )
	{
		this.atmosphereRising = atmosphereRising;
	}

	public long getLastWheaterUpdate( )
	{
		return lastWheaterUpdate;
	}

	public void setLastWheaterUpdate( long lastWheaterUpdate )
	{
		this.lastWheaterUpdate = lastWheaterUpdate;
	}

	public ArrayList< AlarmList > getAlarmList( )
	{
		return alarmList;
	}

	public void setAlarmList( ArrayList< AlarmList > alarmList )
	{
		this.alarmList = alarmList;
	}

	/**
	 * 
	 * @param name
	 *            Returns the AlarmList according to the secondary key
	 * @return
	 */
	public AlarmList getAlarmListByName( String name )
	{
		for( AlarmList element : alarmList )
		{
			if( element.getNameOfAlarmEdit( ).equals( name ) )
			{
				return element;
			}
		}
		return null;
	}

	/**
	 * Override an existing AlarmList by name
	 * 
	 * @param name
	 *            secondary Key of the element, who needs to replaced
	 * @param item
	 *            The element, who replaces an old element
	 */
	public void setAlarmListByName( String name, AlarmList item )
	{
		for( int i = 0; i < alarmList.size( ); i++ )
		{
			if( alarmList.get( i ).getNameOfAlarmEdit( ).equals( name ) )
			{
				alarmList.set( i, item );
				return;
			}
		}
	}

	/**
	 * Return the specific Element
	 * 
	 * @param The
	 *            primary key, who needs to be returned
	 * @return
	 */
	public AlarmList getAlarmListByTime( String time )
	{
		for( AlarmList element : alarmList )
		{
			if( element.getAlarmTime( ).equals( time ) )
			{
				return element;
			}
		}
		return null;
	}

	/**
	 * Returns true, if the element excised or otherwise false
	 * 
	 * @param time
	 *            Returns true or false according to this parameter
	 * @return
	 */
	public boolean isAlarmListByTime( String time )
	{
		for( int i = 0; i < alarmList.size( ); i++ )
		{
			if( alarmList.get( i ).getAlarmTime( ).equals( time ) )
			{
				return true;
			}
		}
		return false;
	}

	/**
	 * 
	 * @param name
	 *            primary key of the element, who needs to replaced
	 * @param item
	 *            The element, who replaces an old element
	 * @return
	 */
	public boolean setAlarmListByTime( String time, AlarmList item )
	{
		for( int i = 0; i < alarmList.size( ); i++ )
		{
			if( alarmList.get( i ).getAlarmTime( ).equals( time ) )
			{
				alarmList.set( i, item );
				return true;
			}
		}
		return false;
	}

	/**
	 * Deletes a specific AlarmList
	 * 
	 * @param time
	 *            Deletes the Alarmlist according to the primary key
	 */
	public void deleteAlarmListByTime( String time )
	{
		for( int i = 0; i < alarmList.size( ); i++ )
		{
			if( alarmList.get( i ).getAlarmTime( ).equals( time ) )
			{
				alarmList.remove( i );
				return;
			}
		}

	}

	public MainScreen getMainScreen( )
	{
		return mainScreen;
	}

	public void setMainScreen( MainScreen mainScreen )
	{
		this.mainScreen = mainScreen;
	}

	public AlarmSettings getAlarmSettings( )
	{
		return alarmSettings;
	}

	public void setAlarmSettings( AlarmSettings alarmSettings )
	{
		this.alarmSettings = alarmSettings;
	}

	public static GetWoeid getGetWoeid( )
	{
		return getWoeid;
	}

	public static void setGetWoeid( GetWoeid yahooWeatherTask )
	{
		Data.getWoeid = yahooWeatherTask;
	}

	public static GetWeather getGetWeather( )
	{
		return getWeather;
	}

	public static void setGetWeather( GetWeather getWeather )
	{
		Data.getWeather = getWeather;
	}

	public static TimerHandler getTimerHandler( )
	{
		return timerHandler;
	}

	public static void setTimerHandler( TimerHandler timerHandler )
	{
		Data.timerHandler = timerHandler;
	}

	public String getLastUsedAlert( )
	{
		return lastUsedAlert;
	}

	public void setLastUsedAlert( String lastUsedAlert )
	{
		this.lastUsedAlert = lastUsedAlert;
	}

	public HashMap< String, String > getTemp_chooseMusik( )
	{
		return temp_chooseMusik;
	}

	public void setTemp_chooseMusik( HashMap< String, String > temp_chooseMusik )
	{
		this.temp_chooseMusik = temp_chooseMusik;
	}

	public MediaPlayer getMediaPlayer( )
	{
		return mediaPlayer;
	}

	public void setMediaPlayer( MediaPlayer mediaPlayer )
	{
		this.mediaPlayer = mediaPlayer;
	}

	public ArrayAdapter< String > getAdapterListViewMain( )
	{
		return adapterListViewMain;
	}

	public void setAdapterListViewMain( ArrayAdapter< String > adapterListViewMain )
	{
		this.adapterListViewMain = adapterListViewMain;
	}

}
